/* Given integer a > 0, we are looking for integers b, c > 0 such that
 *
 *    1     1/b + 1/c
 *   --- = ------------.
 *    a     1 - 1/(bc)
 *
 * Let b = a + k, this can be reduced to
 *
 *            1+a^2
 *   c = a + ------- .
 *              k
 * 
 * It follows that b + c = 2*a + p + q, where p, q are positive integers and
 * p*q = 1+a^2. Thus we can factorize (1+a^2) and find the closest pair of
 * factors (p, q) to get the answer.
 */

#include <stdio.h>

int main()
{
    unsigned int a, s, p;
    while (scanf("%d", &a) == 1)
    {
        s = a * a + 1;
        for (p = a; p >= 1; p--)
        {
            if (s % p == 0)
                break;
        }
        printf("%u\n", 2*a+p+s/p);
    }
    return 0;
}
